include(ExternalProject)

set(GFLAGS_SRC_DIR ${PROJECT_SOURCE_DIR}/3rd/glog)

ExternalProject_Add(GLOG_PRJ
  PREFIX ${PROJECT_SOURCE_DIR}/build
  SOURCE_DIR  ${GFLAGS_SRC_DIR}
  CONFIGURE_COMMAND
    ${CMAKE_COMMAND} ${GFLAGS_SRC_DIR}
    -DBUILD_SHARED_LIBS=ON
    -DCMAKE_INSTALL_PREFIX=${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
    -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
    -DWITH_UNWIND=OFF
    -DBUILD_TESTING=OFF
  #INSTALL_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
  CMAKE_ARGS
    -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
    -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}
    -DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}
    -DCMAKE_CXX_STANDARD_REQUIRED=${CMAKE_CXX_STANDARD_REQUIRED}
  #通过使用 CMAKE_CACHE_ARGS 选项将 C++ 编译器标志传递到外部项目
  CMAKE_CACHE_ARGS -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
  BUILD_ALWAYS 1
  INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install
)

